package com.example.busshop.service;

import com.example.busshop.common.service.LogicService;
import com.example.busshop.dao.BusinessDao;
import com.example.busshop.dao.OrderDao;
import com.example.busshop.dao.ShopDao;
import com.example.busshop.entity.Business;
import com.example.busshop.entity.Order;
import com.example.busshop.entity.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Service
public class BusinessService extends LogicService<BusinessDao, Business,Long> {
    public BusinessService(@Autowired BusinessDao dao) {
        super(dao);
    }
    @Resource
    OrderDao orderDao;
    @Transactional
    public Shop createShop(Long Id,String name){
        Business business=getDAO().getReferenceById(Id);
        Shop shop=business.createShop(name);
        shop.setBusiness(business);
        getDAO().save(business);
        return shop;
    }

    public Set<Shop> allShop(Long Id){
        Business business=getDAO().getReferenceById(Id);
        Set<Shop> shop=business.getShops();
        return shop;
    }

}
